package base.thread_demo.demo08_04;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * public static void yield():暂停当前正在执行的线程，谦让其它线程的执行。
 * 让多个线程的执行更和谐，但是不能靠它保证一人一次。
 */
public class YieldThreadDemo {
    private static final Logger log = LoggerFactory.getLogger(YieldThreadDemo.class);

    public static void main(String[] args) {
        new YieldThread("林青霞").start();
        new YieldThread("刘意").start();
    }





    static class YieldThread extends Thread {
        public YieldThread(String name){
            super(name);
        }

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                log.info("{}:{}", getName(), i);
                Thread.yield();
            }
        }
    }
}
